import {extend, localize} from 'vee-validate'
import { required, email, min, length, confirmed,is_not } from 'vee-validate/dist/rules'


import zh from 'vee-validate/dist/locale/zh_CN.json'
extend('username', email)
extend('min', min)
extend('length', length)
extend('confirmed', confirmed)
extend('required', required)
extend('is_not', is_not)


// extend('minmax', {
//   validate(value, {length}) {
//     return length >= args.min && length <= args.max;
//   },
//   params: ['3', '6']
// });


extend('name', {
    validate: value => {
      console.log((/^\d+/).test(value))
      return !(/^\d+/).test(value)
    },
    message: '不能以纯数字为昵称'
  })

localize('zh_CN',{
    // 使用扩展运算符，扩展中文包
    messages: {
      ...zh.messages,
      // 全局定义message
      required: '请输入{_field_}'
    },
    // 与validation-provider中的name对应
    // key为name, value为对应的中文field名称
    names: {
      username: '邮箱',
      password: '密码',
      name: '昵称',
      code: '验证码',
      name: '昵称',
      repassword: '确认密码',
      title:'标题'
    },
    // 针对不同的name，定义不同的message消息
    fields: {
      username: {
        username: '请输入正确的{_field_}',
        required: '请输入{_field_}',
        confirmed: '密码不匹配'
      },
      name: {
        min: (field, { length }) => {
          return `请在${field}输入至少${length}个字符`
        }
      }
    }
    })





